//
// Created by Tony on 2024/6/14.
//

#ifndef RT_CODE_MEMBER_H
#define RT_CODE_MEMBER_H

#include "AccessFlag.h"
#include <memory>
#include <string>

namespace RtCode {

using std::shared_ptr;
using std::string;
using std::weak_ptr;
class Class;

class Member {
    string mName;
    AccessFlag mAccessFlag;
    weak_ptr<Class> mOwnerClass;

public:
    explicit Member(string name) : mName(std::move(name)), mAccessFlag(0) {}

    void setOwnerClass(const shared_ptr<Class>& clazz) { this->mOwnerClass = clazz; }
    shared_ptr<Class> getOwnerClass() const { return mOwnerClass.lock(); }

    void setName(const string& name) { this->mName = name; }
    const string& getName() { return mName; }

    void setAccessFlag(AccessFlag accessFlags) { this->mAccessFlag = accessFlags; }
    void addAccessFlag(uint16_t flag) { mAccessFlag.addFlag(flag); }
    AccessFlag& getAccessFlag() { return mAccessFlag; }
    bool isStatic() { return mAccessFlag.isFlag(AccessFlag::STATIC); }
    bool isNative() { return mAccessFlag.isFlag(AccessFlag::NATIVE); }
    bool isPublic() { return mAccessFlag.isFlag(AccessFlag::PUBLIC); }
};

} // namespace RtCode

#endif // RT_CODE_MEMBER_H
